package org.particles.domain.world;

import org.particles.domain.Vector2D;

/**
 * disposes of particle in 2D world. 
 */
public class DisposeOutOfBoundResolver implements OutOfWorldBoundResolver {
	private double minX;
	private double maxX;
	private double minY;
	private double maxY;

	public DisposeOutOfBoundResolver(
			final double minX, final double maxX,
			final double minY, final double maxY) {
		this.minX = minX;
		this.maxX = maxX;
		this.minY = minY;
		this.maxY = maxY;
	}
	
	@Override
	public void resolve(final World world, final int particleIndex) {
		final Vector2D place = (Vector2D) world.getParticles().get(particleIndex).getSpacePlace();
		if(place.getX() < minX || place.getX() > maxX
				|| place.getY() < minY || place.getY() > maxY) {
			world.removeParticleAt(particleIndex);
		}
	}

}
